package com.example.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.studyapplication.R;

/**
 * @Description:
 * @Author: 葛浩杰
 * @Version: 1.0 2021/4/12
 */
public class LazyFragment extends Fragment {

    private final String TAG = "LazyFragment";
    private boolean isLoaded = false;

    View rootView;
    TextView tv_tip_num;

    public static LazyFragment newInstance(int num){
        Bundle bundle = new Bundle();
        bundle.putInt("num",num);
        LazyFragment lazyFragment = new LazyFragment();
        lazyFragment.setArguments(bundle);
        return lazyFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        Log.e(TAG, "onCreate");
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.e(TAG, "onCreateView");
        rootView = inflater.inflate(R.layout.fragment_lazy, container, false);
        tv_tip_num = rootView.findViewById(R.id.tv_tip_num);
        tv_tip_num.setText(getArguments().get("num") + "");
        return rootView;
    }

    @Override
    public void onStart() {
        Log.e(TAG, "onStart");
        super.onStart();
    }

    @Override
    public void onResume() {
        Log.e(TAG, "onResume");
        //每次可见的时候才会执行方法
        if(!isLoaded){
            //加载数据
            isLoaded = true;
        }
        super.onResume();
    }

    @Override
    public void onPause() {
        Log.e(TAG, "onPause");
        super.onPause();
    }

    @Override
    public void onStop() {
        Log.e(TAG, "onStop");
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        Log.e(TAG, "onDestroyView");
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        Log.e(TAG, "onDestroy");
        super.onDestroy();
    }

    @Override
    public void onAttach(@NonNull Context context) {
        Log.e(TAG, "onAttach");
        super.onAttach(context);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        Log.e(TAG, "onActivityCreated");
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onDetach() {
        Log.e(TAG, "onDetach");
        super.onDetach();
    }

    @Override
    public void onAttachFragment(@NonNull Fragment childFragment) {
        Log.e(TAG, "onAttachFragment");
        super.onAttachFragment(childFragment);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        Log.e(TAG, "onViewCreated");
        super.onViewCreated(view, savedInstanceState);
    }

}
